package com.example.ffepeg.ffeAdder;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.util.Scanner;

public class TestVideTime {
    public static void main(String[] args) {
      String url = "D:\\javaXM\\FFEpeg\\src\\main\\resources\\out\\7e917d3d-f810-4d68-8b33-fd716393a89e.mp4";
        try {
            Process process = Runtime.getRuntime().exec(
                    "ffprobe -i " + url+ " -show_entries format=duration -v quiet -of csv=\"p=0\""
            );

            // 读取输出
            try (Scanner scanner = new Scanner(process.getInputStream()).useDelimiter("\\A")) {
                if (scanner.hasNext()) {
                    String durationStr = scanner.next().trim();
                    double duration = Double.parseDouble(durationStr); // 注意：这里应该用double而不是int，因为时长可能不是整数
                    System.out.println("视频时长: " + duration + " 秒");
                }
            }
        }catch (Exception e){
            System.out.println("获取时长失败");
        }
    }
}
